package com.example.rabbit;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.listener.api.ChannelAwareMessageListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DesituteConsumer implements ChannelAwareMessageListener {

    @Override
    @RabbitListener(queuesToDeclare = @Queue("destituteQueue"), concurrency = "10")
    public void onMessage(Message message, Channel channel) {
        Long tag = message.getMessageProperties().getDeliveryTag();
        // 确认消费
        try {
            String destituteQueue = new String(message.getBody());
            channel.basicAck(tag, true);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

}